package com.whty.mongodemo;

import com.whty.mongodemo.holder.VertxHolder;
import com.whty.mongodemo.mongo.MongoVerticle;
import com.whty.mongodemo.web.HttpServerVerticle;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.DeploymentOptions;
import io.vertx.core.Promise;
import lombok.extern.slf4j.Slf4j;

@Slf4j
public class MainVerticle extends AbstractVerticle {

  @Override
  public void start(Promise<Void> startPromise) throws Exception {
    VertxHolder.init(vertx);
    vertx.deployVerticle(new MongoVerticle(), new DeploymentOptions().setWorker(true))
      .onSuccess(s -> {
        log.info("MongoVerticle发布成功，准备启动http服务");
        vertx.deployVerticle(new HttpServerVerticle());
      })
      .onFailure(throwable -> log.error("发布MongoVerticle失败：" + throwable.getMessage(), throwable));
  }
}
